using MicroMsg.Manager;
using MicroMsg.Plugin.Shake.Scene;
using MicroMsg.Resource.@string;
using MicroMsg.Storage;
using MicroMsg.UI.ImageFilter;
using MicroMsg.UI.Page;
using MicroMsg.UI.Util;
using System;
using System.Diagnostics;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
namespace MicroMsg.UI.UserContrl
{
	public class ShakePlguinSetCtrl : PluginSettingBaseCtrl
	{
		internal Grid LayoutRoot;
		internal ClickableLayout shake_startShake;
		internal ClickableLayout shake_help;
		internal ClickableLayout shake_changeBk;
		internal ClickableLayout shake_useOriginalBk;
		internal MMToggleSwitch shake_toggle_sound;
		internal MMToggleSwitch shake_toggle_vibrate;
		private bool _contentLoaded;
		public ShakePlguinSetCtrl()
		{
			this.InitializeComponent();
			base.add_Loaded(new RoutedEventHandler(this.page_Loaded));
		}
		private void button_Click(object sender, RoutedEventArgs e)
		{
			Button button = sender as Button;
			if (button == this.shake_startShake)
			{
				this.startShake();
				return;
			}
			if (button == this.shake_help)
			{
				this.shakeHelp();
				return;
			}
			if (button == this.shake_changeBk)
			{
				this.changeBk();
				return;
			}
			if (button == this.shake_useOriginalBk)
			{
				this.changeOriginBk();
			}
		}
		private void startShake()
		{
			object[] pData = new object[]
			{
				default(object),
				"/source/plugin/shake/ui/shakepage.xaml"
			};
			LocationServiceTipPage.GotoThisPage(pData);
			for (int i = 0; i < PageManager.getInstance().basePageList.get_Count(); i++)
			{
				if (PageManager.getInstance().basePageList.get_Item(i) is ShakePage)
				{
					PageManager.getInstance().PopPage();
					return;
				}
			}
		}
		private void shakeHelp()
		{
			object[] pData = new object[]
			{
				default(object),
				"/source/plugin/shake/ui/shakehelppage.xaml"
			};
			LocationServiceTipPage.GotoThisPage(pData);
		}
		private void changeBk()
		{
			this.changeBackground_Click(null, null);
		}
		private void changeOriginBk()
		{
			this.restoreBackground_Click(null, null);
		}
		private void restoreBackground_Click(object sender, EventArgs e)
		{
			ConfigMgr.smethod_0<ShakeConfig>().nShakeImgID = 0u;
			ConfigMgr.smethod_0<ShakeConfig>().bShakeCustomImg = false;
			ConfigMgr.save<ShakeConfig>(false);
			MessageBoxManager.ShowToast(strings.Shake_Set_Default_Backgound_OK, 2500, null, false);
		}
		private void changeBackground_Click(object sender, EventArgs e)
		{
			MMMessageBox mMMessageBox = MMMessageBox.Show(null, strings.Shake_Change_Pic_Confirm, true, strings.ChatSendPicDlgTakePhoto, strings.ChatSendPicDlgImgLib);
			mMMessageBox.ReturnEvent = new DlgReturnEvent(this.SelectPicDlgReturn);
		}
		public void SelectPicDlgReturn(DlgReturnEventArg dlgReturnEventArg_0)
		{
			switch (MMMessageBox.GetUserClickResult(dlgReturnEventArg_0))
			{
			case 0:
				this.takePhoto();
				return;
			case 1:
				this.chooserPicture();
				return;
			default:
				return;
			}
		}
		private void takePhoto()
		{
			ToolFunction.GotoPageForUserControl("/Source/UI/ImageFilter/ImageFilterPage.xaml", new object[]
			{
				new ImageFilterConfig(new ImageFilterCallBack(this.saveBackgroundImage), ImageFilterGetPicMode.GetPicMode_Choose_With_Take, 480, 480, null)
				{
					GetPicMode = ImageFilterGetPicMode.GetPicMode_Take_Photo,
					isSaveToAlbum = ImageFilterMgr.IsSettingAutoSavePhotos(),
					isNeedFilter = false
				}
			}, false);
		}
		private void chooserPicture()
		{
			ToolFunction.GotoPageForUserControl("/Source/UI/ImageFilter/ImageFilterPage.xaml", new object[]
			{
				new ImageFilterConfig(new ImageFilterCallBack(this.saveBackgroundImage), ImageFilterGetPicMode.GetPicMode_Choose_With_Take, 480, 480, null)
				{
					GetPicMode = ImageFilterGetPicMode.GetPicMode_Choose_Exist,
					isNeedFilter = true
				}
			}, false);
		}
		private void saveBackgroundImage(Stream resultData)
		{
			if (resultData != null && resultData.get_Length() > 0L)
			{
				resultData.Seek(0L, 0);
				ConfigMgr.smethod_0<ShakeConfig>().bShakeCustomImg = true;
				ConfigMgr.save<ShakeConfig>(false);
				byte[] array = new byte[resultData.get_Length()];
				resultData.Read(array, 0, (int)resultData.get_Length());
				ShakeStorage.saveImg(array);
				BitmapImage bitmapImage = new BitmapImage();
				bitmapImage.SetSource(resultData);
				MessageBoxManager.ShowToast(strings.Shake_Set_Backgound_OK, 2500, null, false);
				return;
			}
		}
		private void checkedStateChanged(object sender, bool isCheckOn)
		{
			if (sender == this.shake_toggle_sound)
			{
				ConfigMgr.smethod_0<ShakeConfig>().bIsShakeSoundOn = isCheckOn;
				ConfigMgr.save<ShakeConfig>(false);
				this.shake_toggle_sound.IsChecked = isCheckOn;
				return;
			}
			if (sender == this.shake_toggle_vibrate)
			{
				ConfigMgr.smethod_0<ShakeConfig>().bIsShakeVibrateOn = isCheckOn;
				ConfigMgr.save<ShakeConfig>(false);
				this.shake_toggle_vibrate.IsChecked = isCheckOn;
			}
		}
		public void page_Loaded(object sender, RoutedEventArgs e)
		{
			this.shake_toggle_sound.IsChecked = ConfigMgr.smethod_0<ShakeConfig>().bIsShakeSoundOn;
			OnToggleStateChanged onToggleStateChanged = new OnToggleStateChanged(this.checkedStateChanged);
			MMToggleSwitch expr_28 = this.shake_toggle_sound;
			expr_28.onToggleStateChanged = (OnToggleStateChanged)Delegate.Combine(expr_28.onToggleStateChanged, onToggleStateChanged);
			this.shake_toggle_sound.Text = strings.Shake_Prompt_Sound_Effect;
			this.shake_toggle_vibrate.IsChecked = ConfigMgr.smethod_0<ShakeConfig>().bIsShakeVibrateOn;
			this.shake_toggle_vibrate.Text = strings.Set_Common_ToggleVibrate;
			MMToggleSwitch expr_79 = this.shake_toggle_vibrate;
			expr_79.onToggleStateChanged = (OnToggleStateChanged)Delegate.Combine(expr_79.onToggleStateChanged, onToggleStateChanged);
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/Plugin/Shake/UI/ShakePlguinSetCtrl.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.shake_startShake = (ClickableLayout)base.FindName("shake_startShake");
			this.shake_help = (ClickableLayout)base.FindName("shake_help");
			this.shake_changeBk = (ClickableLayout)base.FindName("shake_changeBk");
			this.shake_useOriginalBk = (ClickableLayout)base.FindName("shake_useOriginalBk");
			this.shake_toggle_sound = (MMToggleSwitch)base.FindName("shake_toggle_sound");
			this.shake_toggle_vibrate = (MMToggleSwitch)base.FindName("shake_toggle_vibrate");
		}
	}
}
